package testGuava.example.testGuava;

import com.google.common.base.Preconditions;
import org.junit.Test;

/**
 * @ClassName : org.example.testGuava.PreconditionsTest
 * @Description : 类描述
 * Created by cyd on 2021-09-15 16:00:30
 */
public class PreconditionsTest {

    @Test
    public void testNull() {
        String param = null;
        Preconditions.checkNotNull(param, "not null allowed");
        System.out.println("pass the preconditions");
    }

    /**
     * 条件验证，很方便
     */
    @Test
    public void test02() {
        Student jack = new Student("jack");
        Student mike = new Student("mike");

        Preconditions.checkArgument(!"jack".equals(mike.getStudentName()));

        Preconditions.checkArgument(!"jack".equals(mike.getStudentName()),
                "jack not allowed");
        Preconditions.checkArgument(!"jack".equals(jack.getStudentName()),
                "jack not allowed");
        System.out.println("pass the preconditions");
    }
}
